<template>
    <el-dialog title="编辑秒杀商品信息" width="30%" center v-model="props.editShow" @close="hideAEdit">
        <!-- :rules="rules" -->
        <el-form :model="form" status-icon label-width="120px" class="demo-ruleForm">
            <el-form-item label="商品名称:" prop="brandName">
                {{ props.nowName }}
            </el-form-item>
            <el-form-item label="货号:">NO.</el-form-item>
            <el-form-item label="商品价格:">￥0</el-form-item>
            <el-form-item prop="flashPromotionPrice" label="秒杀价格:" label-width="120px">
                <el-input v-model="form.flashPromotionPrice"></el-input>
            </el-form-item>
            <el-form-item label="剩余数量:">0</el-form-item>
            <el-form-item prop="flashPromotionCount" label="秒杀数量:" label-width="120px">
                <el-input v-model="form.flashPromotionCount"></el-input>
            </el-form-item>
            <el-form-item prop="flashPromotionLimit" label="限购数量:" label-width="120px">
                <el-input v-model="form.flashPromotionLimit"></el-input>
            </el-form-item>
            <el-form-item prop="sort" label="排序:" label-width="120px">
                <el-input v-model="form.sort"></el-input>
            </el-form-item>
        </el-form>
        <el-button @click="hideAEdit">取消</el-button>
        <el-button type="primary" @click="sureEdit">确定</el-button>
    </el-dialog>
</template>

<script setup lang="ts">
import { marketing } from "@/api";
import { ElMessage, ElMessageBox } from "element-plus";
import { defineProps, defineEmits, reactive, toRefs, ref } from "vue"
import { useRoute } from "vue-router";


const route = useRoute()

const props = defineProps({
    editShow: {
        type: Boolean,
        default: false
    },
    nowName: {
        type: String,
        dafault: ""
    },
    nowId: {
        type: Number,
        default: 0
    },
    nowProductId: {
        type: Number,
        default: 0
    }
})
const emit = defineEmits(['hideEdit'])

const state = reactive({
    form: {
        keyword: "",
        flashPromotionCount: "",
        flashPromotionPrice: "",
        flashPromotionLimit: "",
        sort: ""
    }
})


const hideAEdit = () => {
    emit("hideEdit")
}

const sureEdit = () => {
    ElMessageBox.confirm(
        '确定要进行添加操作?',
        '提示',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {
        if (route.query.flashPromotionId && route.query.flashPromotionSessionId) {
            marketing.editFlashProductRelation({
                flashPromotionCount: state.form.flashPromotionCount,
                flashPromotionId: +route.query.flashPromotionId,
                flashPromotionLimit: state.form.flashPromotionLimit,
                flashPromotionPrice: state.form.flashPromotionPrice,
                flashPromotionSessionId: +route.query.flashPromotionSessionId,
                id: props.nowId,
                productId: props.nowProductId,
                sort: state.form.sort
            }).then(res => {
                if (res.code === 200) {
                    ElMessage.success("操作成功")
                    hideAEdit()
                }
            })

        }
    }).catch(() => {
    })
}

const { form } = toRefs(state)
</script>

<style scoped>

</style>